﻿// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;

namespace ICSharpCode.SharpDevelop.Gui.ObjectBrowser
{
	public class ObjectBrowserNavigateBackward : AbstractMenuCommand
	{
		public override bool IsEnabled {
			get {
				return ObjectBrowserPad.Instance.CanNavigateBackward;
			}
		}
		public override void Run()
		{
			ObjectBrowserPad.Instance.NavigateBackward();
		}
	}
	
	public class ObjectBrowserNavigateForward : AbstractMenuCommand
	{
		public override bool IsEnabled {
			get {
				return ObjectBrowserPad.Instance.CanNavigateForward;
			}
		}
		public override void Run()
		{
			ObjectBrowserPad.Instance.NavigateForward();
		}
	}
	
	public class ObjectBrowserCollapseAll : AbstractMenuCommand
	{
		public override bool IsEnabled {
			get { return true; }
		}
		public override void Run()
		{
			ObjectBrowserPad.Instance.CollapseAll();
		}
	}
	
	#region Class browser filter
	public class SelectObjectBrowserFilter : AbstractMenuCommand
	{
		ToolBarDropDownButton dropDownButton;
		
		public override void Run()
		{
		}
		
		protected override void OnOwnerChanged(EventArgs e)
		{
			base.OnOwnerChanged(e);
			dropDownButton = (ToolBarDropDownButton)Owner;
			MenuService.AddItemsToMenu(dropDownButton.DropDownItems, this, "/SharpDevelop/Pads/ObjectBrowser/Toolbar/SelectFilter");
		}
	}
	
	public class ShowBaseAndDerivedTypes : AbstractCheckableMenuCommand
	{
		public override bool IsChecked {
			get {
				return (ObjectBrowserPad.Instance.Filter & ObjectBrowserFilter.ShowBaseAndDerivedTypes) == ObjectBrowserFilter.ShowBaseAndDerivedTypes;
			}
			set {
				if (value) {
					ObjectBrowserPad.Instance.Filter |= ObjectBrowserFilter.ShowBaseAndDerivedTypes;
				} else {
					ObjectBrowserPad.Instance.Filter &= ~ObjectBrowserFilter.ShowBaseAndDerivedTypes;
				}
			}
		}
	}
	
	
	public class ShowProjectReferences : AbstractCheckableMenuCommand
	{
		public override bool IsChecked {
			get {
				return (ObjectBrowserPad.Instance.Filter & ObjectBrowserFilter.ShowProjectReferences) == ObjectBrowserFilter.ShowProjectReferences;
			}
			set {
				if (value) {
					ObjectBrowserPad.Instance.Filter |= ObjectBrowserFilter.ShowProjectReferences;
				} else {
					ObjectBrowserPad.Instance.Filter &= ~ObjectBrowserFilter.ShowProjectReferences;
				}
			}
		}
	}
	
	public class ShowPublicMembers : AbstractCheckableMenuCommand
	{
		public override bool IsChecked {
			get {
				return (ObjectBrowserPad.Instance.Filter & ObjectBrowserFilter.ShowPublic) == ObjectBrowserFilter.ShowPublic;
			}
			set {
				if (value) {
					ObjectBrowserPad.Instance.Filter |= ObjectBrowserFilter.ShowPublic;
				} else {
					ObjectBrowserPad.Instance.Filter &= ~ObjectBrowserFilter.ShowPublic;
				}
			}
		}
	}
	
	public class ShowProtectedMembers : AbstractCheckableMenuCommand
	{
		public override bool IsChecked {
			get {
				return (ObjectBrowserPad.Instance.Filter & ObjectBrowserFilter.ShowProtected) == ObjectBrowserFilter.ShowProtected;
			}
			set {
				if (value) {
					ObjectBrowserPad.Instance.Filter |= ObjectBrowserFilter.ShowProtected;
				} else {
					ObjectBrowserPad.Instance.Filter &= ~ObjectBrowserFilter.ShowProtected;
				}
			}
		}
	}
	
	public class ShowPrivateMembers : AbstractCheckableMenuCommand
	{
		public override bool IsChecked {
			get {
				return (ObjectBrowserPad.Instance.Filter & ObjectBrowserFilter.ShowPrivate) == ObjectBrowserFilter.ShowPrivate;
			}
			set {
				if (value) {
					ObjectBrowserPad.Instance.Filter |= ObjectBrowserFilter.ShowPrivate;
				} else {
					ObjectBrowserPad.Instance.Filter &= ~ObjectBrowserFilter.ShowPrivate;
				}
			}
		}
	}
	
	public class ShowOtherMembers : AbstractCheckableMenuCommand
	{
		public override bool IsChecked {
			get {
				return (ObjectBrowserPad.Instance.Filter & ObjectBrowserFilter.ShowOther) == ObjectBrowserFilter.ShowOther;
			}
			set {
				if (value) {
					ObjectBrowserPad.Instance.Filter |= ObjectBrowserFilter.ShowOther;
				} else {
					ObjectBrowserPad.Instance.Filter &= ~ObjectBrowserFilter.ShowOther;
				}
			}
		}
	}
	
	#endregion
	
	
	#region ObjectBrowser search strip commands
	public class ObjectBrowserSearchTerm : AbstractComboBoxCommand
	{
		ComboBox comboBox;
		
		protected override void OnOwnerChanged(EventArgs e)
		{
			base.OnOwnerChanged(e);
			ToolBarComboBox toolbarItem = (ToolBarComboBox)base.ComboBox;
			comboBox = toolbarItem.ComboBox;
			comboBox.DropDownStyle = ComboBoxStyle.DropDown;
			comboBox.TextChanged  += ComboBoxTextChanged;
		}
		
		void ComboBoxTextChanged(object sender, EventArgs e)
		{
			ObjectBrowserPad.Instance.SearchTerm = comboBox.Text;
			Run(); // TODO: Enable live search via option
		}
		
		public override void Run()
		{
			ObjectBrowserPad.Instance.StartSearch();
		}
	}
	
	public class ObjectBrowserCommitSearch : AbstractMenuCommand
	{
		public override void Run()
		{
			ObjectBrowserPad.Instance.StartSearch();
		}
	}
	
	public class ObjectBrowserCancelSearch : AbstractMenuCommand
	{
		public override bool IsEnabled {
			get {
				return ObjectBrowserPad.Instance.IsInSearchMode;
			}
		}
		public override void Run()
		{
			ObjectBrowserPad.Instance.CancelSearch();
		}
	}
	#endregion
}
